import 'package:flutter/material.dart';
import 'package:kq_flutter_core_widget/utils/kq_screen_util.dart';

/// 页面指示器
///
/// <=1页时，默认不显示
///
/// @author 周卓
class KqPageIndicator extends StatelessWidget {
  /// 当前页码
  final int index;

  /// 总页数
  final int count;

  const KqPageIndicator({Key? key, required this.index, required this.count})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    List<Widget> items = [];
    if (count > 1) {
      Duration duration = const Duration(milliseconds: 150);
      for (int i = 0; i < count; i++) {
        items.add(ClipRRect(
          borderRadius: BorderRadius.all(Radius.circular(20.r)),
          child: AnimatedContainer(
            width: index == i ? 12.r : 6.r,
            height: 6.r,
            color: Colors.white.withOpacity(index == i ? 1 : 0.45),
            duration: duration,
          ),
        ));
        if (i < count - 1) {
          items.add(SizedBox(
            width: 6.r,
          ));
        }
      }
    }
    return Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: items,
    );
  }
}
